// JavaScript Document
function OnSubmitForm(url) {
	document.appForm.action = url;
	document.appForm.submit();
	return true;
}

function checkCheckBox() {
	var theForm = document.appForm;
	if (theForm.elements[i].name == 'cid[]') {
		theForm.elements[i].checked = checked;
		if (theForm.elements[i].checked = true) {
			window.alert(this.value);
		}
	}
}

var checked = false;
function checkedAll() {
	var theForm = document.appForm;
	if (checked == false) {
		checked = true;
		// theForm.checkValue.value = theForm.elements.length;
	} else {
		checked = false;
		// theForm.checkValue.value = 0;
	}

	var countCheckBox = 0;
	for (i = 0; i < theForm.elements.length; i++) {
		if (theForm.elements[i].name == 'cid[]') {
			theForm.elements[i].checked = checked;
			countCheckBox++;
		}
	}

	if (checked == true) {
		theForm.checkValue.value = countCheckBox;
	} else {
		theForm.checkValue.value = 0;
	}
}
function requestAdd(url, id) {
	$('#process').css('display','block');
	$.ajax({
		url : url,
		success : function(a) {
			// console.log(a);
			$(id).removeClass("add-friend-button").addClass("request-friend");
			$('#process').css('display','none');
		}
	})
}

function acceptRequest(url, id) {
	$.ajax({
		url : url,
		success : function(a) {
			$(id).removeClass("accept-cancel").addClass("accept-cancel2");
			setTimeout(function() {
				$("#numberRequest").trigger("click");
				val = parseInt($("#number").html());
				if (val > 0) {
					$("#number").html(val - 1);
				}

			}, 1000);
		}
	})
}
function ajaxAddStatus(url) {
	status = $('#status').val();
	$.ajax({
		url : url,
		data : {
			"status" : status
		},
		success : function(a) {
			$("#model #contentPost").html(status);
			$("#pre-status").prepend($('#model').html());
		}
	})
}
function ajaxDeleteStatus(url, id) {

	$.ajax({
		url : url,
		success : function(a) {
			$(id).css("-webkit-animation", "effectDelete 1s alternate");
			setTimeout(function() {
				$(id).css("display", "none");
			}, 1000);
		}
	})
}
function ajaxSendRequestChallenge(url,url2,idGame) {
	user_id = $("#group_id").val();
	$.ajax({
		url : url,
		data : {
			"user_receive" : user_id,
			"link_app" : window.location.pathname
		},
		success : function(a) {
		}
	})
	
	$.ajax({
		url : url2,
		data : {
			"idGame" : idGame,
		},
		success : function(a) {
		}
	})
}

function ajaxAddPlayed(url2,idGame) {
	$.ajax({
		url : url2,
		data : {
			"idGame" : idGame,
		},
		success : function(a) {
		}
	})
}


function acceptRequestChallenge(url, id) {
	$.ajax({
		url : url,
		success : function(a) {
			$("#iconChallenge").trigger("click");
			val = parseInt($("#numberChallenge").html());
			if (val > 0) {
				$("#numberChallenge").html(val - 1);
			}
			window.location = $("#link_challenge").html();

		}
	})
}

function displayVideo(src,url2, idVideo){
	$('#videoScreen').css('display','block');
	$('#playVideo1').css('display','block');
	$('#playVideo').css('display','block');
	$('#closeVideo').css('display','block');
	//$('#sourceVideo').attr('src',src);
	html = '<video width="730" height="420" controls ><source src="'+src+'"Your browser does not support the video tag </video >' ;
	$('#playVideo').empty();
	$('#playVideo').append(html);
	
	$.ajax({
		url : url2,
		data : {
			"idGame" : idVideo,
		},
		success : function(a) {
		}
	})

}

function closeVideo(){
	$('#videoScreen').css('-webkit-animation','hideScreen 1s ') ;
	$('#playVideo').css('display','none');
	$('#playVideo1').css('-webkit-animation','closeVideo 1s ') ;
	setTimeout(function(){
		$('#playVideo1').css('display','none');
		$('#videoScreen').css('display','none');
		$('#playVideo1').removeAttr("style");
		$('#videoScreen').removeAttr("style");
	},1000);
	
	$('#closeVideo').css('display','none');
	$('#playVideo').empty();
}